package com.hc.music.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hc.music.common.R;
import com.hc.music.dao.CommentMapper;
import com.hc.music.entity.Comment;
import com.hc.music.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper,Comment> implements CommentService {
    @Autowired
    CommentMapper commentMapper;
    @Override
    public R addComment(Comment comment) {
        int i = commentMapper.insert(comment);
        if(i > 0){
            return R.success("评论成功");
        }else {
            return R.error("评论失败");
        }
    }

    @Override
    public R updateCommentMsg(Comment comment) {
        int i = commentMapper.updateById(comment);
        if(i > 0){
            return R.success("点赞成功");
        }else {
            return R.error("点赞失败");
        }
    }

    @Override
    public R deleteComment(Integer id) {
        int i = commentMapper.deleteById(id);
        if(i > 0){
            return R.success("删除评论成功");
        }else {
            return R.error("删除评论失败");
        }
    }

    @Override
    public R commentOfSongId(Integer songId) {
        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("song_id",songId);
        return R.success(null, commentMapper.selectList(queryWrapper));
    }

    @Override
    public R commentOfSongListId(Integer songListId) {
        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("song_list_id",songListId);
        return R.success(null, commentMapper.selectList(queryWrapper));
    }
}
